ποΈ SkyrimNet Memory Storage System (SQLite-Based)
SkyrimNet uses a persistent, lightweight SQLite database to store NPC memories, enabling characters to remember events across sessions β even after saving, quitting, or rebooting the game.
π§± What is SQLite?β
SQLite is a fast, file-based database engine that stores structured data in a single .db
file β no server required.
- β Zero configuration β it runs in-process with your game or mod.
- β Cross-platform β works on Windows, Linux, and Steam Deck.
- β Reliable and lightweight β used by apps like Firefox, Discord, and Android.
- β SQL-compliant β allows rich querying and filtering via standard SQL syntax.
In SkyrimNet, this means you get permanent memory storage that:
- Survives between game loads
- Supports fast search and recall
- Doesn't require external services or internet
π§ Memory Table Structureβ
Each NPC memory is stored as a row in the memories
table.
Example Schemaβ
CREATE TABLE memories (
id INTEGER PRIMARY KEY AUTOINCREMENT,
actor_uuid TEXT NOT NULL,
memory_type TEXT, -- EXPERIENCE, RELATIONSHIP, etc.
content TEXT, -- Main narrative summary
details TEXT, -- Optional longer description
emotion TEXT, -- e.g., fearful, joyful, angry
importance_score REAL, -- Between 0.0 and 1.0
location TEXT, -- Specific place (e.g., "Whiterun Market")
tags TEXT, -- Serialized array (JSON or comma-separated)
embedding BLOB, -- 384-dimensional float vector (MiniLM-L6-v2)
game_time INTEGER, -- When this memory occurred
timestamp INTEGER DEFAULT CURRENT_TIMESTAMP
);
𧬠Embedding Storageβ
Each memory is embedded as a 384-dimensional vector using MiniLM-L6-v2. This vector is stored in a BLOB
field, enabling fast similarity search via a vector index (e.g., FAISS or HNSW).
This allows SkyrimNet to:
- Retrieve memories by semantic similarity
- Rank relevant memories for behavior or dialogue
- Perform emotionally and contextually aware recall
π Writing & Updatingβ
Memory Creation:β
After a memory segment is generated (via the LLM), it's written into the SQLite DB if:
importance_score >= 0.2
- It passes internal relevance filters
Memory Pruning:β
- Each actor can store up to 1000 memories
- Low-importance memories are purged first
- This is configurable in SkyrimNet's settings
Memory Updates:β
- Memories can be edited post-generation (e.g., emotion corrected)
- Tags can be updated dynamically to support evolving gameplay
π Queryingβ
SkyrimNet queries memory using hybrid filtering:
- Vector similarity (via the embedding)
- SQL filters (e.g., by actor, emotion, tag, or location)
- Time-based filters (e.g., βmemories within the last dayβ)
This enables NPCs to recall things like:
- βWhat have I seen the Prisoner do in Whiterun?β
- βHave I ever felt fear around dragons?β
- βWhen did I last talk to Iggwilv?β
βοΈ Performance Notesβ
- Thread-safe: SQLite access is wrapped in safe async calls
- Low overhead: Indexing and embedding is lightweight (~1ms per memory)
- Optimized for read-heavy workloads β ideal for real-time recall during gameplay
SkyrimNet's memory system is a hybrid architecture involving vector-based semantic storage, keyword tagging, actor-event tracking, and SQLite-based persistence.
π§ Storageβ
- Embedding Model:
MiniLM-L6-v2
- Vector Dimension:
384
- Backend: SQLite with HNSW vector index for fast approximate search
- HNSW Parameters:
ef_construction
:200
M
:16
π Retrieval Logicβ
Memory retrieval uses a weighted scoring function that considers:
Weight Type | Value |
---|---|
Semantic Similarity | 0.35 |
Temporal Proximity | 0.20 |
Actor Involvement | 0.20 |
Emotional Resonance | 0.10 |
Keyword Relevance | 0.10 |
Location Proximity | 0.05 |
Retrieval Thresholdsβ
- Minimum Similarity Score:
0.519999981
- Minimum Relevance Score:
0.569999993
- Minimum Keyword Relevance:
0.180000007
π§ Memory Generationβ
Memories are generated from in-game events segmented by time and density:
- Max Time Gap Between Events:
60
minutes - Min Segment Duration:
10
minutes - Max Segment Duration:
480
minutes - Min Events Per Segment:
5
- Max Events Per Segment:
200
- Min Importance to Store:
0.2
Each memory stores:
- Actor UUID
- Memory Type (e.g.
EXPERIENCE
,FACT
,DIALOGUE
) - Text Content
- Importance (0β1.0)
- Emotion Label
- Location
- Related Actors
- Related Event IDs
- Tags
π‘ Example Use Caseβ
A vampire NPC sees a player feed on a bandit. SkyrimNet logs the event and builds a memory:
"I saw the prisoner feed on a Wood Elf bandit under the moonlight. Their bloodlust awakened something... familiar."
This memory can now influence future dialogue, attitude, or AI behavior.